home *** CD-ROM | disk | FTP | other *** search
- unit TestYAST32Unit1;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls;
-
- type
- TForm1 = class(TForm)
- ShowBtn: TButton;
- Memo1: TMemo;
- RawCheckBox: TCheckBox;
- procedure ShowBtnClick(Sender: TObject);
- private
- procedure Five;
- procedure Four;
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- uses
- HVYAST32;
-
- function StackDumpStr: string;
- var
- i: integer;
- begin
- Result := 'Stackframe-based trace:'#13#10+'Physical Logical';
- for i := 0 to StackDumpCount-1 do
- with StackDump[i] do
- Result := Format('%s'#13#10'%.8x %.8x',
- [Result, DWORD(CallerAdr), PhysicalToLogical(DWORD(CallerAdr))]);
- end;
-
- {$W+} { Make sure the compiler generates stack frames for the following routines }
-
- procedure One;
- var
- Trace: string;
- begin
- { Generate a stack trace, skipping no levels
- The stack trace will be saved in the global StackDump array }
- SaveStackTrace(Form1.RawCheckBox.Checked , 0, nil);
- Trace := StackDumpStr;
-
- { Now report the contents of the StackDump array into the memo }
- Form1.Memo1.Lines.Clear;
- Form1.Memo1.Lines.Add(Trace);
- end;
-
- procedure Two;
- begin
- { OOPS! The compiler does not crate a stack-frame
- for all-assembly routines like this one. }
- asm
- { Create a default stack frame manually }
- PUSH EBP
- MOV EBP, ESP
-
- { Simulate a CALL instruction using PUSH and RET }
- PUSH OFFSET @@ret_addr
- PUSH OFFSET One
- RET
-
- { After the 'call' we get back here }
- @@ret_addr:
-
- { Clean up the stack frame }
- POP EBP
- end;
- end;
-
- procedure Three;
- begin
- { Normal procedure call }
- Two;
- end;
-
- procedure TForm1.Four;
- var
- ProcVarCall: procedure;
- begin
- { Call through a procedure variable }
- ProcVarCall := Three;
- ProcVarCall;
- end;
-
- procedure TForm1.Five;
- var
- EventCall: procedure of object;
- begin
- { Call through an event or method variable }
- EventCall := Four;
- EventCall;
- end;
-
- procedure TForm1.ShowBtnClick(Sender: TObject);
- begin
- { Normal method call }
- Five;
- end;
-
- end.
-